/*------------------------------------------------------------------------------------------------------------------*/
// Initialize Vector/Point Classes
/*------------------------------------------------------------------------------------------------------------------*/
public class pt { 
  float x=0,y=0; 
  pt () {};
  pt (float px, float py) {x = px; y = py;};
  pt make() {return(new pt(x,y));};
  void show(int r) { ellipse(x, y, r, r); }; 
  void showLineTo (pt P) {line(x,y,P.x,P.y); }; 
  void setTo(pt P) { x = P.x; y = P.y; }; 
  void setTo(float px, float py) { x = px; y = py; }; 
  //
  void setToMouse(float x1, float y1) { x = x1; y = y1; }; 
  void write() {println("("+x+","+y+")");};
  void addVec(vec V) {x += V.x; y += V.y;};
  void addScaledVec(float s, vec V) {x += s*V.x; y += s*V.y;};
  void subVec(vec V) {x -= V.x; y -= V.y;};
  void vert() {vertex(x,y);};
  boolean isInWindow() {return(((x<0)||(x>600)||(y<0)||(y>600)));};
  void label(String s, vec D) {text(s, x+D.x,y+D.y);  };
  vec vecTo(pt P) {return(new vec(P.x-x,P.y-y)); };
  float disTo(pt P) {return(sqrt(sq(P.x-x)+sq(P.y-y))); };
  vec vecToMid(pt P, pt Q) {return(new vec((P.x+Q.x)/2.0-x,(P.y+Q.y)/2.0-y)); };
  vec vecToProp (pt B, pt D) {
      vec CB = this.vecTo(B); float LCB = CB.norm();
      vec CD = this.vecTo(D); float LCD = CD.norm();
      vec U = CB.make();
      vec V = CD.make(); V.sub(U); V.mul(LCB/(LCB+LCD));
      U.add(V);
      return(U);  
      };  
  void addPt(pt P) {x+=P.x; y+=P.y;};
  void subPt(pt P) {x-=P.x; y-=P.y;};
  void mul(float f) {x*=f; y*=f;};
  void pers(float d) { y=d*y/(d+x); x=d*x/(d+x); };
  void pers2(float d) { y=d*y/(d+x); };
  void rotateAround(pt P, float a) {
    float tx= (x-P.x)*cos(a) + (y-P.y)*sin(a) + P.x; 
    float ty=-(x-P.x)*sin(a) + (y-P.y)*cos(a) + P.y; 
    x=tx; y=ty;
    };
  } 

public class vec {
  float x=0,y=0; 
  vec () {};  
  vec (float px, float py) {x = px; y = py;};
  vec make() {return(new vec(x,y));};
  void setTo(vec V) { x = V.x; y = V.y; }; 
  void show (pt P) { ellipse(P.x, P.y, 3, 3); line(P.x,P.y,P.x+x,P.y+y); }; 
  void add(vec V) {x += V.x; y += V.y;};
  void addScaled(float m, vec V) {x += m*V.x; y += m*V.y;};
  void sub(vec V) {x -= V.x; y -= V.y;};
  void mul(float m) {x *= m; y *= m;};
  void div(float m) {x /= m; y /= m;};
  void write() {println("("+x+","+y+")");};
  float norm() {return(sqrt(sq(x)+sq(y)));}; 
  void unit() {float n=sqrt(sq(x)+sq(y)); if (n>0.0001) {x/=n; y/=n;};};
  vec left() {return(new vec(-y,x));};
  void back() {x= -this.x; y= -this.y;};
  vec turn(float a) {return(new vec(x*cos(a)-y*sin(a),x*sin(a)+y*cos(a))); };
  } 
  
  
pt midPt(pt A, pt B) {return(new pt((A.x+B.x)/2,(A.y+B.y)/2)); };
vec midVec(vec U, vec V) {return(new vec((U.x+V.x)/2,(U.y+V.y)/2)); };
float dot(vec U, vec V) {return(U.x*V.x+U.y*V.y); };
